﻿using System.Collections.Generic;
using System.Management.Automation;

namespace BO.Management.PowerShell
{
    /// <summary>
    /// Base Cmdlet to manage BO. This class offers infrastructure to connect to BO
    /// </summary>
    public abstract class BaseActionObject<T, U> : BaseBOEObject<T, U>
        where T : BaseObjectProvider<U>
        where U : CrystalDecisions.Enterprise.InfoObject
    {

        [Parameter(ValueFromPipeline = true)]
        public U InputObject { get; set; }


        protected override void FindBoeObject()
        {
            this.ThrowExceptionOnObjectNotFound = true;

            if (this.InputObject == null)
            {
                base.FindBoeObject();
            }
            else
            {
                this.OutputObjectIds.Add(this.InputObject.ID);
                this.WorkWithSingleObject(this.InputObject);
            }
        }

        public override void WorkWithListObjects(List<U> boeObjects)
        {
            foreach (U boeObject in boeObjects)
            {
                this.WorkWithSingleObject(boeObject);
            }
        }

    }
}
